﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using SpiritAlight.SceneManagement;
using SpiritAlight.Character;
using SpiritAlight.Stage;
using SpiritAlight.Input;
using Microsoft.Xna.Framework;
namespace SpiritAlight.Scene
{
    public class GameMain : AScene
    {
        private UnitManager unitManager;
        
        //Texture2D stageBase;
        private StageManager stage = new StageManager();


        /// <summary>
        /// ゲームメインコンストラクタ。
        /// </summary>
        /// <param name="State">初期化されるシーンの状態</param>
        public GameMain(SceneState State)
            : base(State)
        {
            Initialize();
            LoadContents();
        }

        /// <summary>
        /// 初期化メソッド。
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();


            unitManager = new UnitManager(this);
            
            unitManager.Initialize();

            AUnit.IsWall += stage.IsWall;
            DrawObject = DrawActor;
        }

        /// <summary>
        /// リソース読み込みメソッド。
        /// </summary>
        public override void LoadContents()
        {
            base.LoadContents();
            //stageBase = SceneManager.Content.Load<Texture2D>("Map/Field/woods");
            unitManager.LoadContent();
        }

        /// <summary>
        /// 更新メソッド。
        /// </summary>
        public override void Update()
        {
            base.Update();

            unitManager.Update();

            if (InputState.IsKeyboard(Keys.Enter) == Input.DeviceState.Pressed)
            {
                if (NowState == SceneState.Active)
                {
                    base.TransOff();
                }

                if (NowState == SceneState.Hidden)
                {
                    base.TransOn();
                }
                
            }
            Camera.Update();
        }

        /// <summary>
        /// 描画メソッド
        /// </summary>
        public override void Draw()
        {

           // SceneManager.SpriteBatch.Draw(stageBase, -Camera.Position, base.SceneColor);
            unitManager.Draw();

            stage.Draw();

            
        }

        public static Action<Texture2D, Vector2> DrawObject;

        public void DrawActor(Texture2D drawObject, Vector2 position)
        {
            if (drawObject == null)
                return;
            SceneManager.SpriteBatch.Draw(drawObject, position, SceneColor);
        }
    }
}
